/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "StdAfx.h"

class DamageShieldSpellProc : public SpellProc
{
	SPELL_PROC_FACTORY_FUNCTION(DamageShieldSpellProc);

	bool CanProc(Unit *victim, SpellEntry *CastingSpell)
	{
		// Allow only proc for player unit
		if( ! mTarget->IsPlayer() )
			return false;
		return true;
	}

	bool DoEffect(Unit *victim, SpellEntry *CastingSpell, uint32 flag, uint32 dmg, uint32 abs, int *dmg_overwrite, uint32 weapon_damage_type)
	{
		Player *plr = TO_PLAYER(mTarget);

		dmg_overwrite[0] = plr->GetBlockDamageReduction() * (mOrigSpell->EffectBasePoints[0] +1) / 100;

		// plr->GetBlockDamageReduction() returns ZERO if player has no shield equipped
		if( dmg_overwrite[0] == 0 )
			return true;

		return false;
	}
};

void SpellProcMgr::SetupWarrior()
{
	AddByNameHash( SPELL_HASH_DAMAGE_SHIELD, &DamageShieldSpellProc::Create );
}